//
//  LSWTabBar.m
//  BaiSi
//
//  Created by 李善武 on 16/5/10.
//  Copyright © 2016年 李善武. All rights reserved.
//

#import "LSWTabBar.h"
#import "UIView+Frame.h"
@interface LSWTabBar()
@property (nonatomic ,weak) UIButton *plusBtn;
@end
@implementation LSWTabBar
- (UIButton *)plusBtn{
   
    if (_plusBtn == nil) {
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateHighlighted];
        [btn sizeToFit];
        self.plusBtn = btn;
        
        // 添加到tabBar这个父控件
        [self addSubview:btn];
    }

    return _plusBtn;
}

- (void)layoutSubviews{
   
    [super layoutSubviews];
    NSInteger count = self.items.count+1;
    CGFloat btnX = 0;
    CGFloat btnY = 0;
    CGFloat btnW = self.lsw_width/count;
    CGFloat btnH = self.lsw_height;
    
    // 遍历子控件
    int i = 0;
    for (UIControl *tabBarButton  in self.subviews) {
        
        if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            if (i == 2) {
                i += 1;
            }
            
            btnX = btnW * i;
            tabBarButton.frame = CGRectMake(btnX, btnY, btnW, btnH);
            i += 1;
        }
        
    }
    self.plusBtn.frame = CGRectMake(btnW * 2, 0, btnW, btnH);
    
}
@end
